# -*- coding: utf-8 -*-

# graphic-pppoe-client - Easy graphic networking manager
#
# Author: GoTLiuM InSPiRiT <gotlium@gmail.com>
#
# Copyright 2010, GoTLiuM InSPiRiT <gotlium@gmail.com>.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

from os import path

""" Base directory path """
BASE_DIR = path.dirname(__file__).replace('/libraries','')
""" Database path """
DB_DIR = BASE_DIR + '/database.sqlite'
""" SQL files path """
SQL_FILES_DIR = BASE_DIR + '/sql-files'


def fileExists(filename):
	return path.exists(filename)

def putFile(filename, text, mode = 'w'):
	try:
		f = open(filename, mode)
		print >> f, text
		f.close()
		return True
	except:
		return False

def delFile(filename):
	try:
		if fileExists(filename):
			remove(filename)
			return True
	except: pass
	return False

def getFile(filename):
	if fileExists(filename):
		return '' . join(open(filename).readlines())
	else:
		return ""

def getFileArr(filename):
	if fileExists(filename):
		return map(lambda x: x.strip(), open(filename).readlines())
	else:
		return ""
